/*
 * Copyright 2009 Jesse McLaughlin (nzjess@gmail.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.travelfusion.xmlclient.xobject;

import java.io.Serializable;
import java.util.Date;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * Instances of this class encapsulate errors returned by the TRAVELfusion TripPlannerXML service.
 * <p>
 * The service encodes error information as XML attributes on elements in the response. The elements typically
 * correspond to the cause of the error in the original request, eg:
 * 
 * <pre>
 * &lt;CommandList&gt;
 *   &lt;DataValidationFailure&gt;
 *     &lt;StartRouting&gt;
 *       ...
 *       &lt;OutwardDates&gt;
 *         &lt;DateOfSearch ecode=&quot;12-1607&quot; etext=&quot;Invalid date&quot;&gt;13/0A/2X09-00:00&lt;/DateOfSearch&gt;
 *         ...
 * </pre>
 * 
 * @author Jesse McLaughlin (nzjess@gmail.com)
 */
public class XError implements Serializable, IsSerializable {

  private static final long serialVersionUID = 1L;

  private String xpath;
  private String code;
  private String text;
  private String detail;
  private Date date;

  /**
   * For RPC.
   */
  public XError() {}

  /**
   * Constructs a new {@link XError} instance, specifying all the properties that describe the error.
   * 
   * @param xpath The absolute xpath of the element in the response that encoded the error.
   * @param code The value of the "ecode" attribute on the error.
   * @param text The value of the "etext" attribute on the error.
   * @param detail The value of the "edetail" attribute on the error.
   * @param date The value of the "edate" attribute on the error.
   */
  public XError(String xpath, String code, String text, String detail, Date date) {
    this.xpath = xpath;
    this.code = code;
    this.text = text;
    this.detail = detail;
    this.date = date;
  }

  public String getXPath() {
    return xpath;
  }

  public String getCode() {
    return code;
  }

  public String getText() {
    return text;
  }

  public String getDetail() {
    return detail;
  }

  public Date getDate() {
    return date;
  }

  @Override
  public String toString() {
    return "[xpath='" + xpath + "', ecode='" + code + "', etext='" + text + "', edetail='" + detail + "', edate=" + date + "]";
  }
}
